/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import javax.faces.context.FacesContext;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "job_position")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "JobPosition.findAll", query = "SELECT j FROM JobPosition j"),
    @NamedQuery(name = "JobPosition.findByIdJobPosition", query = "SELECT j FROM JobPosition j WHERE j.idJobPosition = :idJobPosition"),
    @NamedQuery(name = "JobPosition.findByDescription", query = "SELECT j FROM JobPosition j WHERE j.description = :description"),
    @NamedQuery(name = "JobPosition.findByValue", query = "SELECT j FROM JobPosition j WHERE j.value = :value")})
public class JobPosition implements Serializable, Comparable<JobPosition>, InternationalizableEntity {
    @OneToMany(mappedBy = "jobPosition", fetch = FetchType.LAZY)
    private List<SearchInterestAreaRequerimentOrOperator> searchInterestAreaRequerimentOrOperatorList;
    @OneToMany(mappedBy = "jobPosition", fetch = FetchType.LAZY)
    private List<SearchProfessionalInfoRequerimentOrOperator> searchProfessionalInfoRequerimentOrOperatorList;
    @OneToMany(mappedBy = "jobPosition", fetch = FetchType.LAZY)
    private List<SearchInterestAreaRequerimentAndOperator> searchInterestAreaRequerimentAndOperatorList;
    @OneToMany(mappedBy = "jobPosition", fetch = FetchType.LAZY)
    private List<SearchProfessionalInfoRequerimentAndOperator> searchProfessionalInfoRequerimentAndOperatorList;
    @OneToMany(mappedBy = "jobPosition", fetch = FetchType.LAZY)
    private List<CandidateInterestArea> candidateInterestAreaList;
    @OneToMany(mappedBy = "jobPosition", fetch = FetchType.LAZY)
    private List<CandidateProfessionalInfo> candidateProfessionalInfoList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_JOB_POSITION")
    private Integer idJobPosition;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "DESCRIPTION")
    private String description;
    @Column(name = "VALUE")
    private Integer value;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "jobPosition", fetch = FetchType.LAZY)
    private List<JobPositionDescription> jobPositionDescriptionList;

    public JobPosition() {
    }

    public JobPosition(Integer idJobPosition) {
        this.idJobPosition = idJobPosition;
    }

    public JobPosition(Integer idJobPosition, String description) {
        this.idJobPosition = idJobPosition;
        this.description = description;
    }

    public Integer getIdJobPosition() {
        return idJobPosition;
    }

    public void setIdJobPosition(Integer idJobPosition) {
        this.idJobPosition = idJobPosition;
    }

    @Override
    public String getDescription() {
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getJobPositionDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(JobPositionDescription cd:getJobPositionDescriptionList()){
//                if(cd.getLanguage().getCode().equals(localeCode)){
//                    resDescription=cd.getDescription();
//                }
//            }
//        }
//        return resDescription;
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    @XmlTransient
    public List<JobPositionDescription> getJobPositionDescriptionList() {
        return jobPositionDescriptionList;
    }

    public void setJobPositionDescriptionList(List<JobPositionDescription> jobPositionDescriptionList) {
        this.jobPositionDescriptionList = jobPositionDescriptionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idJobPosition != null ? idJobPosition.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof JobPosition)) {
            return false;
        }
        JobPosition other = (JobPosition) object;
        if ((this.idJobPosition == null && other.idJobPosition != null) || (this.idJobPosition != null && !this.idJobPosition.equals(other.idJobPosition))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.JobPosition[ idJobPosition=" + idJobPosition + " ]";
    }

    @XmlTransient
    public List<CandidateProfessionalInfo> getCandidateProfessionalInfoList() {
        return candidateProfessionalInfoList;
    }

    public void setCandidateProfessionalInfoList(List<CandidateProfessionalInfo> candidateProfessionalInfoList) {
        this.candidateProfessionalInfoList = candidateProfessionalInfoList;
    }

    @XmlTransient
    public List<CandidateInterestArea> getCandidateInterestAreaList() {
        return candidateInterestAreaList;
    }

    public void setCandidateInterestAreaList(List<CandidateInterestArea> candidateInterestAreaList) {
        this.candidateInterestAreaList = candidateInterestAreaList;
    }

    @XmlTransient
    public List<SearchInterestAreaRequerimentOrOperator> getSearchInterestAreaRequerimentOrOperatorList() {
        return searchInterestAreaRequerimentOrOperatorList;
    }

    public void setSearchInterestAreaRequerimentOrOperatorList(List<SearchInterestAreaRequerimentOrOperator> searchInterestAreaRequerimentOrOperatorList) {
        this.searchInterestAreaRequerimentOrOperatorList = searchInterestAreaRequerimentOrOperatorList;
    }

    @XmlTransient
    public List<SearchProfessionalInfoRequerimentOrOperator> getSearchProfessionalInfoRequerimentOrOperatorList() {
        return searchProfessionalInfoRequerimentOrOperatorList;
    }

    public void setSearchProfessionalInfoRequerimentOrOperatorList(List<SearchProfessionalInfoRequerimentOrOperator> searchProfessionalInfoRequerimentOrOperatorList) {
        this.searchProfessionalInfoRequerimentOrOperatorList = searchProfessionalInfoRequerimentOrOperatorList;
    }

    @XmlTransient
    public List<SearchInterestAreaRequerimentAndOperator> getSearchInterestAreaRequerimentAndOperatorList() {
        return searchInterestAreaRequerimentAndOperatorList;
    }

    public void setSearchInterestAreaRequerimentAndOperatorList(List<SearchInterestAreaRequerimentAndOperator> searchInterestAreaRequerimentAndOperatorList) {
        this.searchInterestAreaRequerimentAndOperatorList = searchInterestAreaRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchProfessionalInfoRequerimentAndOperator> getSearchProfessionalInfoRequerimentAndOperatorList() {
        return searchProfessionalInfoRequerimentAndOperatorList;
    }

    public void setSearchProfessionalInfoRequerimentAndOperatorList(List<SearchProfessionalInfoRequerimentAndOperator> searchProfessionalInfoRequerimentAndOperatorList) {
        this.searchProfessionalInfoRequerimentAndOperatorList = searchProfessionalInfoRequerimentAndOperatorList;
    }

    @Override
    public int compareTo(JobPosition t) {
        return this.getDescription().compareToIgnoreCase(t.getDescription());
    }

    @Override
    public Integer getId() {
        return getIdJobPosition();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getJobPositionDescriptionList();
    }
    
}
